        dojo.require('dojo.parser');
        dojo.require('dojo.data.ItemFileReadStore');
        dojo.require('dojo.data.ItemFileWriteStore');
        dojo.require("dojox.grid.compat._grid.edit");
        dojo.require('dojox.grid.DataGrid');
        dojo.require('dijit.form.Button');
        dojo.require("dijit.Dialog");
        dojo.require("dijit.form.TextBox");
        dojo.require("dijit.form.SimpleTextarea");
        dojo.require("dijit.form.Textarea");
        dojo.require("dijit.form.FilteringSelect");

        var floristsMasterArray = new Array();
        var collectionsMasterArray = new Array();

        // build and initialize arrays for ItemFileWriteStores
        var floristsData = {
            identifier: "id",
            label: 'id',
            items: floristsMasterArray
        };

        var collectionsData = {
            identifier: 'id',
            label: 'id',
            items: []
        };

        var collectionsLayout = [
            { field: "namecell", name: "collection", width:"200px" },
            { field: "pricecell", name: "Price", width:"200px" }
        ];

        // select no florist at start
        var iSelectedflorist = -1;
        var iSelectedcollection = -1;

        var idx = 0;
		var floristidx = 0;
		
        // stuff needed to define catalog grid
        var floristsArray = {
            identifier: "id",
            label: 'ID',
            items: floristsMasterArray
        };
        var floristsLayout = [
            { field: "id", name:"ID", hidden:true },
            { field: "namecell", name: "florist", width:"200px" },
            { field: "loccell", name: "Location", width:"200px" }
        ];
        var floristsQuery = { id: '*'};
        var collectionsQuery = { id: '*'};

        var floristsGrid = null;
        var collectionsGrid = null;
        var data_has_changed = false;

//////////////////////////////////////////////////////////////////////////////////////////////////////////

        function formatfloristNamecell( florist )
        {
            var str = '<strong><span id="entry_name">' + florist.name + '</span></strong><br>';
            str = str + 'Phone:<strong>' + florist.phone + '</strong><br>';
            str = str + 'Fax:<strong>' + florist.fax + '</strong><br>';
            str = str + 'Email:<strong>' + florist.email + '</strong><br>';
            return str;
        }

        function formatfloristLoccell( florist )
        {
            var str = '<strong><span id="entry_name">' + florist.address + '</span></strong><br>';
            str = str + '<span>' + florist.city + ', ';
            str = str + florist.state + ' ' + florist.zip + '</span>';
            return str;
        }

        function getfloristForId(id)
        {
            var numflorists = floristsMasterArray.length;
            var ii;
            for( ii=0; ii < numflorists; ii++ )
            {
                if( floristsMasterArray[ii].id == id )
                    return floristsMasterArray[ii];
            }
            return null;
        }

        function getcollectionsForflorist(id)
        {
            var numflorists = collectionsMasterArray.length;
            var ii;
            for( ii=0; ii < numflorists; ii++ )
            {
                if( collectionsMasterArray[ii].florist_id == id )
                    return collectionsMasterArray[ii].collections;
            }
            return null;
        }

        function floristSelected(e)
        {
            var i = e.rowIndex;
            var item = floristsGrid.getItem(i);
            var id = floristsGrid.store.getValues(item, 'id');
            var florist = getfloristForId(id);
            if(florist)
            {
                var collections = getcollectionsForflorist(id);
                if(collections)
                {
                    collectionsData.items = collections;
                    collectionsGrid.store.close();
                    collectionsGrid.setStore(new dojo.data.ItemFileWriteStore({data:collectionsData}));
                }
                else
                {
                    collectionsData.items = [];
                    collectionsGrid.store.close();
                    collectionsGrid.setStore(new dojo.data.ItemFileWriteStore({data:collectionsData}));
                }
            }
        }

        function getSelectedflorist()
        {
            var items = floristsGrid.selection.getSelected();
            if(items.length<1) return null;
            return items[0];
        }

        function getNewfloristId()
        {
			return floristsMasterArray.length;
        }

        function showNewfloristForm()
        {
            // get form
            var floristForm = dijit.byId("floristForm");

            floristForm.execute=addNewflorist;

            // make sure contents are empty
            dijit.byId("florist_name").attr('value','');
            dijit.byId("florist_address").attr('value','');
            dijit.byId("florist_city").attr('value','');
            dijit.byId("florist_state").attr('value','');
            dijit.byId("florist_zip").attr('value','');
            dijit.byId("florist_phone").attr('value','');
            dijit.byId("florist_fax").attr('value','');
            dijit.byId("florist_email").attr('value','');

            floristForm.show();
        }

		function validateFlorist()
		{
            // now we can access via catterer.name, etc.
            var florist_name = dijit.byId('florist_name').attr('value');
            var florist_address = dijit.byId('florist_address').attr('value');
            var florist_city = dijit.byId('florist_city').attr('value');
            var florist_state = dijit.byId('florist_state').attr('value');
            var florist_zip = dijit.byId('florist_zip').attr('value');
            var florist_phone = dijit.byId('florist_phone').attr('value');
            var florist_fax = dijit.byId('florist_fax').attr('value');
            var florist_email = dijit.byId('florist_email').attr('value');
			
			var missingDataFields = new Array();
			var i=0;
			
			if(florist_name=='')
				missingDataFields[i++] = 'Name';
			if(florist_address=='')
				missingDataFields[i++] = 'Address';
			if(florist_city=='')
				missingDataFields[i++] = 'City';
			if(florist_state=='')
				missingDataFields[i++] = 'State';
			if(florist_zip=='')
				missingDataFields[i++] = 'Zip';
			if(florist_phone=='')
				missingDataFields[i++] = 'Phone';
			if(florist_fax=='')
				missingDataFields[i++] = 'Fax';
			if(florist_email=='')
				missingDataFields[i++] = 'Email';
			
			if(missingDataFields.length > 0)
			{
				var str = 'The following fields do not have valid data in them:\n';
				for( i=0; i < missingDataFields.length; i++ )
					str = str + missingDataFields[i] + '\n';
				alert(str);
				return false;
			}
			
			return true;
		}
		
		function validateCollection()
		{
            var collection_name = dijit.byId("item_name").attr('value');
            var collection_description = dijit.byId("item_description").attr('value');
            var collection_units = dijit.byId("item_units").attr('value');
            var collection_cost = dijit.byId("item_cost").attr('value');
			
			var missingDataFields = new Array();
			var i=0;
			
			if(collection_name=='')
				missingDataFields[i++] = 'Name';
			if(collection_description=='')
				missingDataFields[i++] = 'Description';
			if(collection_units=='')
				missingDataFields[i++] = 'Units';
			if(collection_cost=='')
				missingDataFields[i++] = 'Cost';
			
			//^[0-9]+\.[0-9]{0,2}$ for regex match
			// if collection_cost has a dollar sign in it, remove
			if(!collection_cost.match(/^[0-9]+\.[0-9]{0,2}$/))
			{
				alert('Arrangement price must be entered as $XXXX.XX');
				return false;
			}
			
			if(missingDataFields.length > 0)
			{
				var str = 'The following fields do not have valid data in them:\n';
				for( i=0; i < missingDataFields.length; i++ )
					str = str + missingDataFields[i] + '\n';
				alert(str);
				return false;
			}
			
			return true;
		}
		
        function showEditfloristForm()
        {
            // get selected florist
            // get florist form
            var floristForm = dijit.byId("floristForm");

            floristForm.execute=updateflorist;

            // fill florist fields with field values from selected florist
            var florist = getSelectedflorist();
            if(null == florist)
            {
                alert('You must select a florist first');
                return;
            }

            var florist_name = floristsGrid.store.getValues(florist, 'name');
            var florist_address = floristsGrid.store.getValues(florist, 'address');
            var florist_city = floristsGrid.store.getValues(florist, 'city');
            var florist_state = floristsGrid.store.getValues(florist, 'state');
            var florist_zip = floristsGrid.store.getValues(florist, 'zip');
            var florist_phone = floristsGrid.store.getValues(florist, 'phone');
            var florist_fax = floristsGrid.store.getValues(florist, 'fax');
            var florist_email = floristsGrid.store.getValues(florist, 'email');

            dijit.byId("florist_name").attr('value',florist_name);
            dijit.byId("florist_address").attr('value',florist_address);
            dijit.byId("florist_city").attr('value',florist_city);
            dijit.byId("florist_state").attr('value',florist_state);
            dijit.byId("florist_zip").attr('value',florist_zip);
            dijit.byId("florist_phone").attr('value',florist_phone);
            dijit.byId("florist_fax").attr('value',florist_fax);
            dijit.byId("florist_email").attr('value',florist_email);

            floristForm.show();
        }

        function addNewflorist()
        {
			console.log('validating florist');
			if(!validateFlorist()) return;
			
            // generate new id for florist - run thru florists list and get max id
            // and add 1.
			console.log('getting new id');
            var florist_id = getNewfloristId();

            var florist = {};

            florist.id = florist_id;
            florist.name = dijit.byId('florist_name').attr('value');
            florist.address = dijit.byId('florist_address').attr('value');
            florist.city = dijit.byId('florist_city').attr('value');
            florist.state = dijit.byId('florist_state').attr('value');
            florist.zip = dijit.byId('florist_zip').attr('value');
            florist.phone = dijit.byId('florist_phone').attr('value');
            florist.fax = dijit.byId('florist_fax').attr('value');
            florist.email = dijit.byId('florist_email').attr('value');

            florist.namecell = formatfloristNamecell( florist );
            florist.loccell = formatfloristLoccell( florist );

			console.log(florist);
            // now that we have this, let's add it to the florist array
            // do it using the floristsStore.
            var floristsGrid = dijit.byId('floristsGrid');
			console.log(floristsGrid);
            floristsGrid.store.newItem( florist );

            // okay, now that we've added a new florist we need
            // to make a new empty entry in the collectionsMasterArray structure with
            // the right florist id and all.
            var new_collection_group = {florist_id:florist_id,collections:[]};
            collectionsMasterArray.push( new_collection_group );

            // now select this florist and empty out the collections grid
            var florist_idx = findfloristIdxById( florist_id );
            floristsGrid.selection.select( florist_idx );

            collectionsData.items = new_collection_group.collections;
            collectionsGrid.store.close();
            collectionsGrid.setStore(new dojo.data.ItemFileWriteStore({data:collectionsData}));

            data_has_changed = true;
        }

        function findfloristIdxById( florist_id )
        {
            var ii;
            for( ii=0; ii < floristsMasterArray.length; ii++ )
            {
                if( florist_id == floristsMasterArray[ii].id )
                    return ii;
            }
            return -1;
        }

        function findfloristById( florist_id )
        {
            var ii;
            for( ii=0; ii < floristsMasterArray.length; ii++ )
            {
                if( florist_id == floristsMasterArray[ii].id )
                    return floristsMasterArray[ii];
            }
            return null;
        }

        function updateflorist( florist_id )
        {
			if(!validateFlorist()) return;
			
            var florist = getSelectedflorist();

            // now we can access via catterer.name, etc.
            var florist_name = dijit.byId('florist_name').attr('value');
            var florist_address = dijit.byId('florist_address').attr('value');
            var florist_city = dijit.byId('florist_city').attr('value');
            var florist_state = dijit.byId('florist_state').attr('value');
            var florist_zip = dijit.byId('florist_zip').attr('value');
            var florist_phone = dijit.byId('florist_phone').attr('value');
            var florist_fax = dijit.byId('florist_fax').attr('value');
            var florist_email = dijit.byId('florist_email').attr('value');

            floristsGrid.store.setValue( florist, 'name', florist_name );
            floristsGrid.store.setValue( florist, 'address', florist_address );
            floristsGrid.store.setValue( florist, 'city', florist_city );
            floristsGrid.store.setValue( florist, 'state', florist_state );
            floristsGrid.store.setValue( florist, 'zip', florist_zip );
            floristsGrid.store.setValue( florist, 'phone', florist_phone );
            floristsGrid.store.setValue( florist, 'fax', florist_fax );
            floristsGrid.store.setValue( florist, 'email', florist_email );

            var florist_namecell = formatfloristNamecell( florist );
            var florist_loccell = formatfloristLoccell( florist );

            floristsGrid.store.setValue( florist, 'namecell', florist_namecell );
            floristsGrid.store.setValue( florist, 'loccell', florist_loccell );

            floristsGrid.store.fetch();
            floristsGrid.update();

            data_has_changed = true;
        }

        function removecollectionsForflorist(florist_id)
        {
            for( var ii=0; ii < collectionsMasterArray.length; ii++ )
            {
                if( florist_id == collectionsMasterArray[ii].florist_id )
                {
                    collectionsMasterArray.splice( ii, 1 );
                    collectionsData.items = [];
                    collectionsGrid.store.close();
                    collectionsGrid.setStore(new dojo.data.ItemFileWriteStore({data:collectionsData}));
                    return;
                }
            }

        }

        function removeFlorist()
        {
            var florist = getSelectedflorist();
            if(null == florist)
            {
                alert('You have to select an florist');
                return;
            }

            // locate the index of the element in the master collection array
            var florist_id = floristsGrid.store.getValues( florist, 'id' );

            removecollectionsForflorist(florist_id);

            floristsGrid.store.deleteItem(florist);

            // now deselect all of the florists in the collection
            floristsGrid.selection.clear();

            data_has_changed = true;
        }

//////////////////////////////////////////////////////////////////////////////////////////////////////////

        function formatcollectionNameInfo( collection )
        {
            var str  = '<strong><span id="entry_name">'+collection.name+'</span></strong><br>';
            str = str + collection.description;
            return str;
        }

        function formatcollectionPriceInfo( collection )
        {
            var str = '<strong><span>$'+collection.price+' per '+collection.units+'</span></strong>';
            return str;
        }

        function getSelectedcollection()
        {
            var items = collectionsGrid.selection.getSelected();
            if(items.length<1) return null;
            return items[0];
        }

        function showNewcollectionForm()
        {
            // get form
            var collectionForm = dijit.byId("collectionForm");
            collectionForm.execute = addNewcollection;

            // make sure contents are empty
            dijit.byId("item_name").attr('value','');
            dijit.byId("item_description").attr('value','');
            dijit.byId("item_units").attr('value','');
            dijit.byId("item_cost").attr('value','');

            collectionForm.show();
        }

        function showEditcollectionForm()
        {
            // get selected florist
            // get florist form
            var collectionForm = dijit.byId("collectionForm");
            collectionForm.execute = updatecollection;

            // fill florist fields with field values from selected florist
            var collection = getSelectedcollection();
            if(null == collection)
            {
                alert('You must select a collection first');
                return;
            }

            var collection_name = collectionsGrid.store.getValues(collection, 'name');
            var collection_description = collectionsGrid.store.getValues(collection, 'description');
            var collection_units = collectionsGrid.store.getValues(collection, 'units');
            var collection_cost = collectionsGrid.store.getValues(collection, 'price');

            dijit.byId("item_name").attr('value',collection_name);
            dijit.byId("item_description").attr('value',collection_description);
            dijit.byId("item_units").attr('value',collection_units);
            dijit.byId("item_cost").attr('value',collection_cost);

            collectionForm.show();
        }

        function getNewcollectionId()
        {
            // loop through florists and contained collections to get largest collection id
            // and return that number + 1
            var ii;
            var maxId = -1;
            for( ii=0; ii < collectionsMasterArray.length; ii++ )
            {
                for( var jj=0; jj < collectionsMasterArray[ii].collections.length; jj++ )
                {
                    if(maxId < collectionsMasterArray[ii].collections[jj].id)
                        maxId = collectionsMasterArray[ii].collections[jj].id;
                }
            }

            return maxId+1;
        }

        function addNewcollection()
        {
			if(!validateCollection()) return;
			
            // to insert this record into the appropriate place in the list, will need
            // to get the collection array for florist_id (e.g. florist) and assign it to
            // the collection data store.
            newId = getNewcollectionId();

            var collection = {};

            collection.id = newId;
            collection.name = dijit.byId("item_name").attr('value');
            collection.description = dijit.byId("item_description").attr('value');
            collection.units = dijit.byId("item_units").attr('value');
            collection.price = dijit.byId("item_cost").attr('value');

            // format the fancy cells
            collection.namecell = formatcollectionNameInfo( collection );
            collection.pricecell = formatcollectionPriceInfo( collection );

            // insert.
            var collectionsGrid = dijit.byId('collectionsGrid');
            collectionsGrid.store.newItem( collection );

            data_has_changed = true;
        }

        function updatecollection()
        {
			if(!validateCollection()) return;
			
            var collection_name = dijit.byId("item_name").attr('value');
            var collection_description = dijit.byId("item_description").attr('value');
            var collection_units = dijit.byId("item_units").attr('value');
            var collection_cost = dijit.byId("item_cost").attr('value');

            var collection = getSelectedcollection();

            collectionsGrid.store.setValue( collection, 'name', collection_name );
            collectionsGrid.store.setValue( collection, 'description', collection_description );
            collectionsGrid.store.setValue( collection, 'units', collection_units );
            collectionsGrid.store.setValue( collection, 'price', collection_cost );

            var collection_namecell = formatcollectionNameInfo( collection );
            var collection_pricecell = formatcollectionPriceInfo( collection );

            collectionsGrid.store.setValue( collection, 'namecell', collection_namecell );
            collectionsGrid.store.setValue( collection, 'pricecell', collection_pricecell );

            collectionsGrid.store.fetch();
            collectionsGrid.update();

            data_has_changed = true;
        }

        function removecollection()
        {
            var collection = getSelectedcollection();
            if(null == collection)
            {
                alert("You must select a collection first");
            }
            // hope this works and doesn't blow chow...'
            collectionsGrid.store.deleteItem(collection);
            collectionsGrid.store.fetch();
            collectionsGrid.update();

            data_has_changed = true;
        }

        function dumpflorists()
        {
            for( var i=0; i < floristsMasterArray.length; i++ )
            {
                console.log('id:' + floristsMasterArray[i].id );
                console.log('name:' + floristsMasterArray[i].name );
            }
        }

        function dumpcollections()
        {
            for( var ii=0; ii < collectionsMasterArray.length; ii++ )
            {
                console.log('florist id:'+collectionsMasterArray[ii].florist_id)
                for( var jj=0; jj < collectionsMasterArray[ii].collections.length; jj++ )
                {
                    console.log('collection name:'+collectionsMasterArray[ii].collections[jj].name);
                }
            }
        }

        function floristsToXML()
        {
            var str = '<florists>';
            for( var i=0; i < floristsMasterArray.length; i++ )
            {
                str = str + '<florist>';
                str = str + '<id>' + floristsMasterArray[i].id + '</id>';
                str = str + '<name>' + floristsMasterArray[i].name + '</name>';
                str = str + '<address>' + floristsMasterArray[i].address + '</address>';
                str = str + '<city>' + floristsMasterArray[i].city + '</city>';
                str = str + '<state>' + floristsMasterArray[i].state + '</state>';
                str = str + '<zip>' + floristsMasterArray[i].zip + '</zip>';
                str = str + '<phone>' + floristsMasterArray[i].phone + '</phone>';
                str = str + '<fax>' + floristsMasterArray[i].fax + '</fax>';
                str = str + '<email>' + floristsMasterArray[i].email + '</email>';
                str = str + '</florist>';
            }
            str = str + '</florists>';
            return str;
        }

        function collectionsToXML()
        {
            var str = '<florist_collections>';
            for( var ii=0; ii < collectionsMasterArray.length; ii++ )
            {
                str = str + '<florist>';
                str = str + '<id>' + collectionsMasterArray[ii].id + '</id>';
                str = str + '<collections>';
                for( var jj=0; jj < collectionsMasterArray[ii].collections.length; jj++ )
                {
                    str = str + '<collection>';
                    str = str + '<name>' + collectionsMasterArray[ii].collections[jj].name + '</name>';
                    str = str + '<description>' + collectionsMasterArray[ii].collections[jj].description + '</description>';
                    str = str + '<units>' + collectionsMasterArray[ii].collections[jj].units + '</units>';
                    str = str + '<price>' + collectionsMasterArray[ii].collections[jj].price + '</price>';
                    str = str + '</collection>';
                }
                str = str + '</collections>';
                str = str + '</florist>';
            }
            str = str + '</florist_collections>';
            return str;
        }

        // XML-ize this for update
        function floristsAndcollectionsToXML()
        {
            var florists_xml = floristsToXML();
            var collections_xml = collectionsToXML();
            return '<floristsAndcollections>' + florists_xml + collections_xml + '<floristsAndcollections>';
        }

        function onSubmit()
        {
            var str = floristsAndcollectionsToXML();
            alert(str);
            return false;
        }

        function getFloristsAndcollectionsForBranch( branch_number )
        {
            dojo.xhrGet( {
                url:'/index/floristsandcollections/branch_number/'+branch_number,
                handleAs: 'json',
                load: function(florists) {
                    // now reload zee array in here...

                    // #1 - delete the existing floristsMasterArray - do this using the datastore?
                    // #2 - delete the existing collectionsMasterArray

                    floristsMasterArray = new Array();
                    collectionsMasterArray = new Array();
                    if(null != florists)
                    {
                        for( var i=0; i < florists.length; i ++ )
                        {
                            var florist = florists[i];

                            var nc = {
                                id:i,
                                name:florist.name,
                                address:florist.address,
                                city:florist.city,
                                state:florist.state,
                                zip:florist.zip,
                                phone:florist.phone,
                                fax:florist.phone,
                                email:florist.email,
                                collections:'none'
                            };

                            nc.namecell = formatfloristNamecell(nc);
                            nc.loccell = formatfloristLoccell(nc);
                            console.log(nc.name);
                            floristsMasterArray[i] = nc;

                            // now ...
                            collectionsMasterArray[i] = { florist_id:i, collections:[] };

                            var collections = florist.collections;
                            var collectionId = 0;
                            for( var j=0; j < collections.length; j++ )
                            {
                                collectionId++;
                                var collection = collections[j];
                                console.log('collection: '+collection.name);
                                var nm = {
                                    id:collectionId,
                                    name:collection.name,
                                    description:collection.description,
                                    units:collection.units,
                                    price:collection.price
                                };

                                // format collection items
                                nm.namecell = formatcollectionNameInfo( nm );
                                nm.pricecell = formatcollectionPriceInfo( nm );

                                // assign nm to collectionsMasterArray[i].collections[j]
                                collectionsMasterArray[i].collections[j] = nm;
                            }
                        }
                    }
                    // reload the florists grid
                    floristsData.items = floristsMasterArray;
                    floristsGrid.store.close();
                    floristsGrid.selection.clear();
                    floristsGrid.setStore(new dojo.data.ItemFileWriteStore({data:floristsData}));

                    // reload the collections grid
                    collectionsData.items = [];
                    collectionsGrid.store.close();
                    collectionsGrid.setStore(new dojo.data.ItemFileWriteStore({data:collectionsData}));
                }
            } );
        }

        function savefloristsAndcollectionsForBranch( branch )
        {
            var result = false;
            // assign str to the form's hidden field
            // dojo.xhrPost() and get the response back into
            // a local var so we can return a true or false

            var xmlstr = '<florists>';

            xmlstr = xmlstr + '<branch>' + branch + '</branch>';

            // merge collectionsMasterArray into floristsMasterArray
            for(var i=0; i < floristsMasterArray.length; i++ )
            {
                florist = floristsMasterArray[i];

                xmlstr = xmlstr + '<florist>';
                xmlstr = xmlstr + '<name>' + florist.name + '</name>';
                xmlstr = xmlstr + '<address>' + florist.address + '</address>';
                xmlstr = xmlstr + '<city>' + florist.city + '</city>';
                xmlstr = xmlstr + '<state>' + florist.state + '</state>';
                xmlstr = xmlstr + '<zip>' + florist.zip + '</zip>';
                xmlstr = xmlstr + '<phone>' + florist.phone + '</phone>';
                xmlstr = xmlstr + '<fax>' + florist.fax + '</fax>';
                xmlstr = xmlstr + '<email>' + florist.email + '</email>';

                xmlstr = xmlstr + '<collections>';
                // find collections list for florist
                var collections = getcollectionsForflorist( floristsMasterArray[i].id );

                for( var j=0; j < collections.length; j++ )
                {
                    collection = collections[j];
                    xmlstr = xmlstr + '<collection>';
                    xmlstr = xmlstr + '<name>' + collection.name + '</name>';
                    xmlstr = xmlstr + '<description>' + collection.description + '</description>';
                    xmlstr = xmlstr + '<units>' + collection.units + '</units>';
                    xmlstr = xmlstr + '<price>' + collection.price + '</price>';
                    xmlstr = xmlstr + '</collection>';
                }

                xmlstr = xmlstr + '</collections>';

                xmlstr = xmlstr + '</florist>';
            }
            xmlstr = xmlstr + '</florists>';
            
            var florists_hidden_element = document.getElementById('floristsXML');
            florists_hidden_element.value = xmlstr;
            
            // "submit" the form to wing the florists/collections and branch id to the controller method
            dojo.xhrPost ({
                    // The page that parses the POST request
                    url:'/index/updatefloristsandcollections',

                    // Name of the Form we want to submit
                    form: 'updateform',

                    // handle reply as JSON
                    handleAs: 'json',

                    // Loads this function if everything went ok
                    load: function (data) {
                            // Put the data into the appropriate <div>
                            console.log(data.status);
                            if(data.status == "OK")
                                result = true;
                            else
                                result = false;
                    },
                    // Call this function if an error happened
                    error: function (error) {
                            console.error ('Error: ', error);
                    }
                }
            );

            return result;
        }

        function saveFloristsAndCollectionsForSelectedBranch()
        {
            var branch_number = document.getElementById('branch_number');
            result = savefloristsAndcollectionsForBranch( current_branch );
			data_has_changed = false;
            return false;
        }

        function getFloristsAndcollectionsForSelectedBranch()
        {
            var branch_number = document.getElementById('branch_number');
            if(data_has_changed)
            {
				alert('You have made changes to the florists or packages for this branch.  You must save these changes before proceeding.');
				branch_number.value = current_branch;
				return;
            }

            current_branch = branch_number.value;
            getFloristsAndcollectionsForBranch(current_branch);
        }

		// these are there to pre-select florist and arrangements from stored_florist and stored_collection
		function selectFlorist(floristName)
		{
		}
		
		function selectArrangements(arrangements)
		{	
		}
		
        var floristsStore =  new dojo.data.ItemFileWriteStore({data:floristsData});
        var collectionsStore =  new dojo.data.ItemFileWriteStore({data:collectionsData});

        dojo.addOnLoad( function() {

        floristDlg = dijit.byId("floristForm");

        dojo.connect(dijit.byId("btnNewFlorist"), "onClick", showNewfloristForm );
        dojo.connect(dijit.byId("btnEditFlorist"), "onClick", showEditfloristForm );
        dojo.connect(dijit.byId("btnDeleteFlorist"), "onClick", removeFlorist );

        dojo.connect(dijit.byId("btnNewCollection"), "onClick", showNewcollectionForm );
        dojo.connect(dijit.byId("btnEditCollection"), "onClick", showEditcollectionForm );
        dojo.connect(dijit.byId("btnDeleteCollection"), "onClick", removecollection );

        floristsGrid = dijit.byId('floristsGrid');
        collectionsGrid = dijit.byId('collectionsGrid');

        dojo.connect( floristsGrid, "onRowClick", floristSelected );

        getFloristsAndcollectionsForBranch(current_branch);
    });



